package com.kpf.springcloud.controller;

import com.kpf.springcloud.common.ResponseEnum;
import com.kpf.springcloud.common.ResultJson;
import com.kpf.springcloud.exception.BusinessException;
import com.kpf.springcloud.pojo.KpfUser;
import com.kpf.springcloud.pojo.PageResult;
import com.kpf.springcloud.service.IKpfUserService;
import com.kpf.springcloud.utils.GeneralUtil;
import com.kpf.springcloud.vo.KpfUserTopicListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author shiwen
 * @date 2021/2/16
 */
@RestController
public class KpfUserController {

    @Autowired
    private IKpfUserService kpfUserService;

    @GetMapping("/user/queryAll")
    public ResultJson<List<KpfUser>> queryAll() {
        return ResultJson.ok(kpfUserService.queryAll());
    }

    @GetMapping("/user/queryAllMp")
    public ResultJson<List<KpfUser>> queryAllMp() {
        return ResultJson.ok(kpfUserService.queryAll_mp());
    }

    @PostMapping("/user/registerUser")
    public ResultJson<Boolean> registerUser(Long age, String phone, String address, String username, String password) {
        return ResultJson.ok(kpfUserService.registerUser(age, phone, address, username, password));
    }

    @GetMapping("/user/login")
    public ResultJson<KpfUser> login(String phone, String password) {
        return ResultJson.ok(kpfUserService.login(phone, password));
    }

    @PostMapping("/user/modifySelfInfo")
    public ResultJson<Boolean> modifySelfInfo(String headimg, String username, String phone, String password, String address){
        return ResultJson.ok(kpfUserService.modifySelfInfo(headimg, username, phone, password, address));
    }

    @GetMapping("/user/getLoginUserById")
    public ResultJson<KpfUser> getLoginUserById() {
        return ResultJson.ok(kpfUserService.getLoginUserById());
    }

    @PostMapping("/user/setSelfUserId")
    public ResultJson setSelfUserId(int userId) {
        kpfUserService.setSelfUserId(userId);
        return ResultJson.ok();
    }

    /**
     * 这里就不做分页了...直接将所有的帖子内容都拿过来
     */
    @GetMapping("/user/getByUserId")
    public ResultJson<KpfUserTopicListVO> getByUserId() {
        return ResultJson.ok(kpfUserService.getByUserId());
    }

    @GetMapping("/user/getUserList")
    public ResultJson<PageResult> getUserList(int pageNum, int pageSize) {
        return ResultJson.ok(kpfUserService.userList(pageNum, pageSize));
    }

    @PostMapping("/user/deleteUserById")
    public ResultJson deleteUserById(int userId) {
        kpfUserService.deleteUserById(userId);
        return ResultJson.ok();
    }

}